function [Gini,TopShare]=DistApp_Hist_InequalityMeasure(QQ,QW,TopShareQuantile)
[QQ,Ind]=   sort(QQ);
QW      =   QW(Ind);
QW      =   QW/sum(QW);

CDF     =   [0;cumsum(QW)];
AccPct  =   [0;cumsum(QQ.*QW)];
AccPct  =   AccPct/abs(AccPct(end));
[UniVal,UniInd] ...
        =   unique(CDF);

if nargin<3
    TopShareQuantile    =   [0.5];
end
if QW'*QQ<=0
    Gini    =   NaN;
    TopShare=   NaN(size(TopShareQuantile));
else
    pp      =   interp1(CDF(UniInd),AccPct(UniInd),'pchip','pp');
    Int_pp  =   fnder(pp,-1);
    Gini    =   1-2*(ppval(Int_pp,1)-ppval(Int_pp,0));
    TopShare=   1-ppval(pp,1-TopShareQuantile);
end



